package com.hadron.media.slideshow.items 
{
	import temple.media.video.players.VideoPlayer;
	import temple.ui.layout.ScaleMode;

	import com.greensock.TweenMax;
	import com.greensock.easing.Quart;
	import com.hadron.graphics.rectangle.HadronRectangle;

	import flash.events.FullScreenEvent;

	// import components.players.video_player.VideoPlayerControls;
	/**
	 * ...
	 * @author Hadron
	 */
	public class SlideshowVideoItem extends AbstractSlideshowItem
	{
		private var player:VideoPlayer;
		//private var controls:VideoPlayerControls = new VideoPlayerControls();
		private var masker:HadronRectangle;
		private var w:Number;
		private var h:Number;
		
		public function SlideshowVideoItem(url:String, _w:Number = 1100, _h:Number = 425) 
		{
			super();
			this.w = _w;
			this.h = _h;
			player = new VideoPlayer(_w, _h, false, ScaleMode.NO_BORDER);
			//player.background = true;
			//player.backgroundColor = 0xff0000;
			player.volume = .3;
			player.loadUrl(url);
			addChild(player);
			//controls.videoPlayer = player;
			//controls.x = (this.width - controls.width) / 2;
			//controls.y = (this.height - controls.height) - 10;
			//addChild(controls);			
			
			masker = new HadronRectangle(_w, _h, 0, 0);
			addChild(masker);
		}
		
		private function handleFullscreen(e:FullScreenEvent):void 
		{
			/*if (e.fullScreen)
			{
				stage.addChild(player);
				stage.addChild(controls);
				fullscreenBehavior = new LiquidBehavior(player, null, { top:0, bottom:0, left:0, right:0 } );
				controls.x = (player.width - controls.width) / 2;
				controls.y = player.height - controls.height - 5;
			} else {
				fullscreenBehavior.destruct();
				player.x = 0;
				player.y = 0;
				player.width = this.w;
				player.height = this.h;
				addChild(player);
				controls.x = (this.w - controls.width) / 2;
				controls.y = (this.h - controls.height) - 10;
				addChild(controls);
			}*/
		}
		
		override public function transitionIn():void
		{
			super.transitionIn();
			//add masker 
			masker.scaleY = 0;
			this.mask = masker;
			TweenMax.to(masker, 1, { scaleY:1, ease:Quart.easeOut } );
			TweenMax.from(player, 1, { y:'-30', ease:Quart.easeOut, onComplete:transitionInComplete } );
			stage.addEventListener(FullScreenEvent.FULL_SCREEN, handleFullscreen);
		}
		
		override public function transitionOut():void
		{
			super.transitionOut();
			player.stop();
			stage.removeEventListener(FullScreenEvent.FULL_SCREEN, handleFullscreen);
			transitionOutComplete();
		}
	}
}